package yartiss.engine.simulation.system;

import java.util.PriorityQueue;

import yartiss.engine.simulation.IEnergyConsumptionProfile;
import yartiss.engine.simulation.system.schedulable.Job;

/**
 * 
 * @author Younes Chandarli
 * 
 */
public interface ITask {

	/**
	 * Gets the identifier of the task
	 * 
	 * @return task's id
	 */
	public int getId();

	/**
	 * Sets an identifier to the task
	 * 
	 * @param id
	 *            task's identifier to be set
	 */
	void setId(int id);

	/**
	 * Gets the first release time of the task
	 * 
	 * @return task's first release time
	 */
	public long getFirstRelease();

	/**
	 * Sets the first release time of a task
	 * 
	 * @param firstRelease
	 *            first release time
	 */
	void setFirstRelease(long firstRelease);

	/**
	 * Gets the worst-case execution time of the task
	 * 
	 * @return task's WCET
	 */
	public long getWcet();

	/**
	 * Gets the worst-case execution energy consumption of the task
	 * 
	 * @return task's WCEE
	 */
	public long getWcee();

	/**
	 * Gets the relative period of the task
	 * 
	 * @return task's period
	 */
	public long getPeriod();

	/**
	 * Gets the relative deadline of the task
	 * 
	 * @return task's deadline
	 */
	public long getDeadline();

	/**
	 * Gets the priority of the task
	 * 
	 * @return task's priority
	 */
	public int getPriority();

	/**
	 * Sets the priority of the task
	 * 
	 * @param priority
	 *            task's priority to be set
	 */
	public void setPriority(int priority);

	/**
	 * Gets the energy consumption rate of the task rate = wcee / wcet
	 * 
	 * @return task's energy consumption rate
	 */
	public long getEnergyConsumptionRate();

	/**
	 * Gets the energy consumption of the task if executed during a certain
	 * period of time
	 * 
	 * @param time
	 *            number of time's units
	 * @return task's energy consumption
	 */
	public long getEnergyConsumption(long time);

	/**
	 * Gets the laxity (slack time) of a task
	 * 
	 * @return laxity of the task
	 */
	public long getLaxity();

	/**
	 * Duplicates the task's object
	 * 
	 * @return clones task
	 */
	public ITask cloneTask();

	/**
	 * Returns the active jobs of the task
	 * 
	 * @return task's active jobs
	 */
	public PriorityQueue<Job> getActiveJobs();

	/**
	 * Checks if the task has active jobs
	 * 
	 * @return true if there are active jobs, false otherwise
	 */
	public boolean isActive();

	/**
	 * Activates a job of this task with a release time of 'time' units
	 * 
	 * @param time
	 *            time units
	 */
	public void activate(long time);

	/**
	 * Gets the current job of the task, i.e. the first job that has not been
	 * completed
	 * 
	 * @return task's current job
	 */
	public Job getCurrentJob();

	/**
	 * Checks if the task missed its deadline by checking its current job at a
	 * certain instant of time
	 * 
	 * @param time
	 *            time instant
	 * @return true if the task missed its deadline, false otherwise
	 */
	public boolean checkDeadlineMissed(long time);

	/**
	 * Checks if the active job is not the last executed one
	 * 
	 * @return true if the active job is not the last executed one, false
	 *         otherwise
	 */
	public boolean lastExecutedJobHasCompleted();

	/**
	 * Gets the remaining time cost of task's current job
	 * 
	 * @return task's remaining time cost
	 */
	public long getRemainingCost();

	/**
	 * Gets the absolute deadline of the current job of the task according to
	 * the value of the boolean 'nextPeriod'
	 * 
	 * 
	 * @param time
	 *            current instant of time
	 * @param nextPeriod
	 *            if true, next period of the task is calculated. If false,
	 *            current period is calculated
	 * @return task's next deadline
	 */
	public long getNextDeadline(long time, boolean nextPeriod);

	/**
	 * Gets the next activation time of the task
	 * 
	 * @param time
	 *            current time
	 * @return task's next activation time
	 */
	public long getNextActivation(long time);

	/**
	 * Checks if a new job of task can be activated at 'time' instant of time
	 * 
	 * @param time
	 *            current time
	 * @return true if it is activation time, false otherwise
	 */
	public boolean isActivationTime(long time);

	/**
	 * Gets the absolute deadline of the next job of the task
	 * 
	 * @param time
	 *            current instant of time
	 * @return task's next absolute deadline
	 */
	public long getNextAbsoluteDeadline(long time);

	/**
	 * Gets the absolute deadline of the previous job of the task
	 * 
	 * @param time
	 *            current instant of time
	 * @return task's previous absolute deadline
	 */
	public long getPreviousAbsoluteDeadline(long date);

	/**
	 * Gets task's last executed job
	 * 
	 * @return last executed job
	 */
	public Job getLastExecutedJob();

	/**
	 * Sets last executed job of the task
	 * 
	 * @param lastExecutedJob
	 *            the last executed job to set
	 */
	public void setLastExecutedJob(Job lastExecutedJob);

	/**
	 * Gets the type of the task (simple, subtask, graph, ...)
	 * 
	 * @return task's type
	 */
	public String getType();

	public IEnergyConsumptionProfile getEnergyConsumptionProfile();

}
